package com.example.test.Dao;

import com.example.test.bean.BraendType;
import com.example.test.bean.GoodType;
import com.example.test.mapper.GoodTypeMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Primary;

import java.util.List;

@Primary
@Mapper
public interface TypeDao extends GoodTypeMapper {

    //根据id查询brandName
    @Select("SELECT\n" +
            "\ttype_name\n" +
            "FROM\n" +
            "\tgood_type\n" +
            "WHERE\n" +
            "\ttype_id = #{typeId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    String getNameById(Long typeId);

    //根据name查询id
    @Select("SELECT\n" +
            "\ttype_id\n" +
            "FROM\n" +
            "\tgood_type\n" +
            "WHERE\n" +
            "\ttype_name = #{newTypeName}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    Long getIdByName(String newTypeName);

    //根据keyword查询
    @Select("SELECT\n" +
            "\ttype_id,\n" +
            "\ttype_name\n" +
            "FROM\n" +
            "\tgood_type\n" +
            "WHERE\n" +
            "\ttype_name like concat('%',#{keyword},'%')\n" +
            "AND\n" +
            "\tdeleted = 0\n" +
            "LIMIT #{size} OFFSET #{offset}\n")
    List<GoodType> getByKeyword(String keyword, Long size, Long offset);

    //根据id查询
    @Select("SELECT\n" +
            "\ttype_id,\n" +
            "\ttype_name\n" +
            "FROM\n" +
            "\tgood_type\n" +
            "WHERE\n" +
            "\ttype_id = #{typeId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    GoodType getById(Long typeId);

}
